package com.pang.security.auth;

import com.pang.security.dto.Result;
import com.pang.security.dto.ResultCode;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @version 1.0
 * 功能目的描述 ：用于   权限不足时的处理      ========>>>>>>>>>>>
 * @author： pang-yun
 * @date： 2021-06-23 19:39
 */
@Component
public class MyAccessDeniedHandler extends JSONAuthentication implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        Result result=Result.error(ResultCode.NO_PERMISSION);
        this.WriteJSON(request,response,result);
    }
}
